package com.xu.seckillkill.config;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletRequest;

/**
 * @version v1.0
 * @类描述：  用户参数自定义注解HandlerMethodArgumentResolver
 * @项目名称：
 * @包名： com.xu.seckillkill.config
 * @类名称：UserArgument
 * @创建人：YIHANG.XU
 * @创建时间：2021/1/138:54 下午
 * @修改人：YIHANG.XU
 * @修改时间：2021/1/138:54 下午
 * @修改备注：
 * @Copyright
 */
@Slf4j
@Component
public class UserArgument implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        Class<?> parameterType = methodParameter.getParameterType();
        if(parameterType.equals(UserArgument.class)){
            log.info("这是user对象json传入");
          return true;
        }

        return false;
    }

    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer,
                                     NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
        HttpServletRequest nativeRequest = nativeWebRequest.getNativeRequest(HttpServletRequest.class);
       // nativeRequest.getCookies();
        log.info("返回参数");
        return null;
    }
}
